<template>
  <view>

    <view style="padding: 10px;">
      <uni-row>
        <uni-col :span="14">
          <uni-datetime-picker v-model="queryParams.violationDay" @change="onViolationDayChange" type="date" />
        </uni-col>

        <uni-col :span="9" :offset="1">
          <button type="primary" style="height: 37px;line-height: 37px;" @click="addViolationPatrol">违纪登记</button>
        </uni-col>
      </uni-row>

      <uni-list :border="true" style="margin-left: 10px;margin-right: 10px;margin-bottom: 10px">
        <uni-list-item
            thumb-size="lg"
            :title="getDictLabel(violationTypeOptions,item.violationType)"
            :thumb="handleImageUrl(item.cover)"
            :note="'违纪时间：'+item.violationTime"
            v-for="(item,index) in violationPatrolList"
            :key="index"
            @click="goToDetail(item)" link>
          <template v-slot:footer>
            <uni-badge type="success" text="已提交" size="normal" style="align-self: center" :custom-style="{fontSize: '13px'}" />
          </template>
        </uni-list-item>
      </uni-list>
    </view>
  </view>
</template>

<script>
import violationPatrol from "../../api/modules/violationPatrol";
import {getDictByType} from "../../api/modules/sys";
import {getDictLabel} from "../../js/common";
export default {
  data() {
    return {
      queryParams: {
        "violationDay": null,
      },
      violationTypeOptions: null,
      violationPatrolList: [],
    }
  },
  onShow() {
    this.showLoadingByQuery();
    getDictByType("violation_type").then(res=>{
      this.violationTypeOptions = res.data;
      this.getViolationPatrolPage();
    }).catch(error=>{
      this.hideLoading();
      if(this.isEmpty(this.violationTypeOptions)){
        this.toast(this.getErrorResMsg(error,"获取数据失败"));
        this.goBack(1000);
      }
    });
  },
  methods: {
    getDictLabel,
    goToDetail(item) {
      console.log("打开违纪巡查详情",item);
      // 点击事件，跳转到详情页面
      uni.navigateTo({
        url: `/pages_duty/securityStaff/violationPatrolDetail?id=${item.id}`
      });
    },
    getViolationPatrolPage(){
      violationPatrol.getViolationPatrolPageList(this.queryParams).then(res=>{
        this.violationPatrolList = res.data.list;
        this.hideLoading();
      }).catch(()=>{
        this.hideLoading();
      });
    },
    onViolationDayChange(val){
      console.log("onViolationDayChange() day:",val)
      if(!val){
        this.queryParams.violationDay = null;
      }
      this.getViolationPatrolPage();
    },
    del(id){
      retention.delRetention(id).then(res => {
        this.loadRetentionData();
      })
    },
    addViolationPatrol() {
      uni.navigateTo({
        url: "/pages_duty/securityStaff/violationPatrolDetail"
      })
    },
    clickImg(img) {
      uni.previewImage({
        urls: [img], //需要预览的图片http链接列表，多张的时候，url直接写在后面就行了
        current: '', // 当前显示图片的http链接，默认是第一个
        success: function(res) {},
        fail: function(res) {},
        complete: function(res) {},
      })
    },
  }
}
</script>

<style>
</style>
